-- -----------------------------------------------------------------------------
-- cell geometry
-- -----------------------------------------------------------------------------
surface,volume = SurfaceAndVolume(12.5,5,5);

print( "Surface=" .. surface .. " microns^2" );
print( "Volume =" .. volume  .. " microns^3" );

Cm = 1.0; -- microFarad/cm^2

-- -----------------------------------------------------------------------------
-- simulation parameters
-- -----------------------------------------------------------------------------
dt_max = 0.05; -- check chemistry every dt_max at most

-- ---------------------------------------------------------------------
-- Reduced Permeabilities, argument is zeta=FV/RT
-- ---------------------------------------------------------------------
exp = math.exp;

-- Surface * Permeability in micron^3 / s
function SP_K( x )
	return ((3.70714279) * exp( (0.4310085034) * x ) + (1.507274188));
end

-- Surface * Permeability in micron^3 / s
function SP_Cl(x)
	return (1.194531961) * exp( (0.05658342092) * x );
end

-- Surface * Permeability in micron^3 / s

function SP_Na(x)
	return (1.360058333) * exp( (0.05223441992) * x );
end

function SP_H(zeta)
	return 0;
end

Em = -55e-3;


chemistry="chemistry-co2.lua"
effectors="effectors-co2.lua"

-- ---------------------------------------------------------------------
-- auxiliary functions
-- ---------------------------------------------------------------------

-- ---------------------------------------------------------------------
-- go from 0 to 1 
-- ---------------------------------------------------------------------
function smooth(X)
	return 3*X^2 - 2*X^3
end

-- ---------------------------------------------------------------------
-- go from 0 to 1 from t_start, during duration
-- ---------------------------------------------------------------------
function smooth_ramp(t,t_start,duration)
    local t_end = t_start + duration;
    if( t < t_start ) then
        return 0.0;
    end
    
    if( (t>=t_start) and (t < t_end ) ) then
        return smooth( (t-t_start)/duration );
    end
    
    return 1.0;
end

-- ---------------------------------------------------------------------
-- go from 0 to 1 from t_start, during duration
-- ---------------------------------------------------------------------
function smooth_bump(t,t_start,up_duration,plateau_duration,down_duration)
    local t_increase = t_start    + up_duration;
    local t_plateau  = t_increase + plateau_duration;
    local t_end      = t_plateau  + down_duration;

    if( t < t_start ) then
        return 0.0;
    end
    
    if( ( t>= t_start) and (t < t_increase) ) then
        return smooth( (t-t_start) / up_duration );
    end
    
    if( (t>=t_increase) and (t<t_plateau) ) then
        return 1.0;
    end
    
    if( (t>=t_plateau) and ( t < t_end ) ) then
        return 1-smooth( (t-t_plateau)/down_duration );
    end
    
    return 0.0;
    
end

